﻿using System;
using System.Collections.Generic;
using UILib;
using UnityEngine;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient.UI
{
	// Token: 0x0200184E RID: 6222
	internal class XPetMainView : DlgBase<XPetMainView, XPetMainBehaviour>
	{
		// Token: 0x17003960 RID: 14688
		// (get) Token: 0x060102A7 RID: 66215 RVA: 0x003E1178 File Offset: 0x003DF378
		public XFoodSelectorHandler FoodSelectorHandler
		{
			get
			{
				return this.m_FoodSelectorHandler;
			}
		}

		// Token: 0x17003961 RID: 14689
		// (get) Token: 0x060102A8 RID: 66216 RVA: 0x003E1190 File Offset: 0x003DF390
		public XPetSkillHandler SkillHandler
		{
			get
			{
				return this.m_SkillHandler;
			}
		}

		// Token: 0x17003962 RID: 14690
		// (get) Token: 0x060102A9 RID: 66217 RVA: 0x003E11A8 File Offset: 0x003DF3A8
		public override string fileName
		{
			get
			{
				return "GameSystem/PetMainDlg";
			}
		}

		// Token: 0x17003963 RID: 14691
		// (get) Token: 0x060102AA RID: 66218 RVA: 0x003E11C0 File Offset: 0x003DF3C0
		public override int layer
		{
			get
			{
				return 1;
			}
		}

		// Token: 0x17003964 RID: 14692
		// (get) Token: 0x060102AB RID: 66219 RVA: 0x003E11D4 File Offset: 0x003DF3D4
		public override int group
		{
			get
			{
				return 1;
			}
		}

		// Token: 0x17003965 RID: 14693
		// (get) Token: 0x060102AC RID: 66220 RVA: 0x003E11E8 File Offset: 0x003DF3E8
		public override bool autoload
		{
			get
			{
				return true;
			}
		}

		// Token: 0x17003966 RID: 14694
		// (get) Token: 0x060102AD RID: 66221 RVA: 0x003E11FC File Offset: 0x003DF3FC
		public override bool hideMainMenu
		{
			get
			{
				return true;
			}
		}

		// Token: 0x17003967 RID: 14695
		// (get) Token: 0x060102AE RID: 66222 RVA: 0x003E1210 File Offset: 0x003DF410
		public override bool fullscreenui
		{
			get
			{
				return true;
			}
		}

		// Token: 0x17003968 RID: 14696
		// (get) Token: 0x060102AF RID: 66223 RVA: 0x003E1224 File Offset: 0x003DF424
		public override bool pushstack
		{
			get
			{
				return true;
			}
		}

		// Token: 0x060102B0 RID: 66224 RVA: 0x003E1238 File Offset: 0x003DF438
		protected override void Init()
		{
			this.doc = XDocuments.GetSpecificDocument<XPetDocument>(XPetDocument.uuID);
			this.doc.View = this;
			DlgHandlerBase.EnsureCreate<XFoodSelectorHandler>(ref this.m_FoodSelectorHandler, base.uiBehaviour.m_FeedFrame, null, true);
			DlgHandlerBase.EnsureCreate<XPetSkillHandler>(ref this.m_SkillHandler, base.uiBehaviour.m_SkillFrame, null, true);
			DlgHandlerBase.EnsureCreate<PetExpTransferHandler>(ref this.ExpTransferHandler, base.uiBehaviour.m_Bg, false, this);
			DlgHandlerBase.EnsureCreate<PetSkillLearnHandler>(ref this.SkillLearnHandler, base.uiBehaviour.m_Bg, false, null);
			DlgHandlerBase.EnsureCreate<PairsPetSetHandler>(ref this.m_setHandler, base.uiBehaviour.m_Bg, false, null);
		}

		// Token: 0x060102B1 RID: 66225 RVA: 0x003E12E0 File Offset: 0x003DF4E0
		protected override void OnShow()
		{
			base.OnShow();
			base.Alloc3DAvatarPool("XPetMainView");
			this.InitShow();
			this.m_FoodSelectorHandler.ShowBag(false);
			this.doc.Select(this.doc.DefaultPet, true);
		}

		// Token: 0x060102B2 RID: 66226 RVA: 0x003E132D File Offset: 0x003DF52D
		public override void StackRefresh()
		{
			base.StackRefresh();
			base.Alloc3DAvatarPool("XPetMainView");
			this.RefreshPetModel();
			this.m_FoodSelectorHandler.ShowBag(false);
		}

		// Token: 0x060102B3 RID: 66227 RVA: 0x003E1358 File Offset: 0x003DF558
		private void InitShow()
		{
			this.doc.ClearPetAnimation();
			XSingleton<XTimerMgr>.singleton.KillTimer(this._RefreshDataTimerID);
			XSingleton<XTimerMgr>.singleton.KillTimer(this._PlayActionTimerID);
			XSingleton<XTimerMgr>.singleton.KillTimer(this._PlayBubbleTimerID);
		}

		// Token: 0x060102B4 RID: 66228 RVA: 0x003E13A8 File Offset: 0x003DF5A8
		public void UnloadFx(XFx fx)
		{
			bool flag = fx != null;
			if (flag)
			{
				XSingleton<XFxMgr>.singleton.DestroyFx(fx, true);
				fx = null;
			}
		}

		// Token: 0x060102B5 RID: 66229 RVA: 0x003E13D0 File Offset: 0x003DF5D0
		private void UnloadShow()
		{
			this.doc.ClearPetAnimation();
			XSingleton<XTimerMgr>.singleton.KillTimer(this._RefreshDataTimerID);
			XSingleton<XTimerMgr>.singleton.KillTimer(this._PlayActionTimerID);
			XSingleton<XTimerMgr>.singleton.KillTimer(this._PlayBubbleTimerID);
			this._RefreshDataTimerID = 0U;
			this._PlayActionTimerID = 0U;
			this._PlayBubbleTimerID = 0U;
			this.UnloadFx(this._LevelUpFx);
			this.UnloadFx(this._MoodUpFx);
			this.UnloadFx(this._EatUpFx);
			this.UnloadFx(this._GetFx);
			bool flag = base.uiBehaviour.m_PetSnapshot != null;
			if (flag)
			{
				base.uiBehaviour.m_PetSnapshot.RefreshRenderQueue = null;
			}
			base.Return3DAvatarPool();
		}

		// Token: 0x060102B6 RID: 66230 RVA: 0x003E1491 File Offset: 0x003DF691
		protected override void OnHide()
		{
			this.UnloadShow();
			this.doc.HasNewPet = false;
			base.OnHide();
		}

		// Token: 0x060102B7 RID: 66231 RVA: 0x003E14B0 File Offset: 0x003DF6B0
		protected override void OnUnload()
		{
			this.UnloadShow();
			this.doc.View = null;
			this.doc = null;
			DlgHandlerBase.EnsureUnload<PetSkillLearnHandler>(ref this.SkillLearnHandler);
			DlgHandlerBase.EnsureUnload<PetExpTransferHandler>(ref this.ExpTransferHandler);
			DlgHandlerBase.EnsureUnload<XFoodSelectorHandler>(ref this.m_FoodSelectorHandler);
			DlgHandlerBase.EnsureUnload<XPetSkillHandler>(ref this.m_SkillHandler);
			DlgHandlerBase.EnsureUnload<PairsPetSetHandler>(ref this.m_setHandler);
			base.OnUnload();
		}

		// Token: 0x060102B8 RID: 66232 RVA: 0x003E151C File Offset: 0x003DF71C
		public override void RegisterEvent()
		{
			base.uiBehaviour.m_Help.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnHelpClicked));
			base.uiBehaviour.m_Close.RegisterClickEventHandler(new ButtonClickEventHandler(this._OnCloseBtnClick));
			base.uiBehaviour.m_WrapContent.RegisterItemUpdateEventHandler(new WrapItemUpdateEventHandler(this._OnPetListItemUpdated));
			base.uiBehaviour.m_BtnMount.RegisterClickEventHandler(new ButtonClickEventHandler(this._OnMountClicked));
			base.uiBehaviour.m_BtnSkillLearn.RegisterClickEventHandler(new ButtonClickEventHandler(this._OnSkillLearnClicked));
			base.uiBehaviour.m_Activation.RegisterClickEventHandler(new ButtonClickEventHandler(this._OnActivationClicked));
			base.uiBehaviour.m_Throw.RegisterClickEventHandler(new ButtonClickEventHandler(this._OnThrowClicked));
			base.uiBehaviour.m_ExpTransfer.RegisterClickEventHandler(new ButtonClickEventHandler(this._OnExpTransferClicked));
			base.uiBehaviour.m_TravelSet.RegisterClickEventHandler(new ButtonClickEventHandler(this._OnTravelSetClicked));
			base.uiBehaviour.m_MoodClose.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this._OnMoodCloseClick));
			base.uiBehaviour.m_FullDegreeClose.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this._OnFullDegreeCloseClick));
			base.uiBehaviour.m_FullDegreeSp.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this._OnShowFullDegreeTip));
			base.uiBehaviour.m_MoodIcon.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this._OnShowMoodTip));
			base.uiBehaviour.m_Caress.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this._OnCaressClick));
			base.uiBehaviour.m_GoGetPet.ID = ulong.Parse(XSingleton<XGlobalConfig>.singleton.GetValue("PetGoBuyPet"));
			base.uiBehaviour.m_GoGetPet.RegisterLabelClickEventHandler(new LabelClickEventHandler(this._OnGoClick));
			base.uiBehaviour.m_GoGetFeed.ID = ulong.Parse(XSingleton<XGlobalConfig>.singleton.GetValue("PetGoBuyFeed"));
			base.uiBehaviour.m_GoGetFeed.RegisterLabelClickEventHandler(new LabelClickEventHandler(this._OnGoClick));
			base.uiBehaviour.m_PrivilegeBg.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnMemberPrivilegeClicked));
		}

		// Token: 0x060102B9 RID: 66233 RVA: 0x0023F430 File Offset: 0x0023D630
		private void OnMemberPrivilegeClicked(IXUISprite btn)
		{
			DlgBase<XWelfareView, XWelfareBehaviour>.singleton.CheckActiveMemberPrivilege(MemberPrivilege.KingdomPrivilege_Adventurer);
		}

		// Token: 0x060102BA RID: 66234 RVA: 0x003E1764 File Offset: 0x003DF964
		public bool OnHelpClicked(IXUIButton button)
		{
			DlgBase<XCommonHelpTipView, XCommonHelpTipBehaviour>.singleton.ShowHelp(XSysDefine.XSys_Horse);
			return true;
		}

		// Token: 0x060102BB RID: 66235 RVA: 0x003E1784 File Offset: 0x003DF984
		private void _OnGoClick(IXUILabel go)
		{
			XSingleton<XGameSysMgr>.singleton.OpenSystem((XSysDefine)go.ID, 0UL);
		}

		// Token: 0x060102BC RID: 66236 RVA: 0x003E179C File Offset: 0x003DF99C
		private bool _OnCloseBtnClick(IXUIButton go)
		{
			this.SetVisibleWithAnimation(false, null);
			return true;
		}

		// Token: 0x060102BD RID: 66237 RVA: 0x003E17B8 File Offset: 0x003DF9B8
		private void _OnShowFullDegreeTip(IXUISprite iSp)
		{
			bool activeSelf = base.uiBehaviour.m_FullDegreeTip.gameObject.activeSelf;
			if (activeSelf)
			{
				base.uiBehaviour.m_FullDegreeTip.gameObject.SetActive(false);
			}
			else
			{
				base.uiBehaviour.m_FullDegreeTip.gameObject.SetActive(true);
				base.uiBehaviour.m_MoodTip.gameObject.SetActive(false);
				base.uiBehaviour.m_FullDegreeLabel.SetText(XSingleton<UiUtility>.singleton.ReplaceReturn(XSingleton<XStringTable>.singleton.GetString("PET_FULL_DEGREE_TIP")));
			}
		}

		// Token: 0x060102BE RID: 66238 RVA: 0x003E1854 File Offset: 0x003DFA54
		private void _OnShowMoodTip(IXUISprite iSp)
		{
			bool activeSelf = base.uiBehaviour.m_MoodTip.gameObject.activeSelf;
			if (activeSelf)
			{
				base.uiBehaviour.m_MoodTip.gameObject.SetActive(false);
			}
			else
			{
				base.uiBehaviour.m_MoodTip.gameObject.SetActive(true);
				base.uiBehaviour.m_FullDegreeTip.gameObject.SetActive(false);
				PetMoodTipsTable.RowData petMoodTip = this.doc.GetPetMoodTip(this.doc.CurSelectedPet.Mood);
				base.uiBehaviour.m_MoodLabel.SetText(petMoodTip.tips);
				XSingleton<XDebug>.singleton.AddLog("Mood:" + this.doc.CurSelectedPet.Mood, null, null, null, null, null, XDebugColor.XDebug_None);
			}
		}

		// Token: 0x060102BF RID: 66239 RVA: 0x003E192C File Offset: 0x003DFB2C
		private void _OnMoodCloseClick(IXUISprite iSp)
		{
			base.uiBehaviour.m_MoodTip.gameObject.SetActive(false);
		}

		// Token: 0x060102C0 RID: 66240 RVA: 0x003E1946 File Offset: 0x003DFB46
		private void _OnFullDegreeCloseClick(IXUISprite iSp)
		{
			base.uiBehaviour.m_FullDegreeTip.gameObject.SetActive(false);
		}

		// Token: 0x060102C1 RID: 66241 RVA: 0x003E1960 File Offset: 0x003DFB60
		private void _OnCaressClick(IXUISprite iSp)
		{
			this.doc.ReqPetTouch();
		}

		// Token: 0x060102C2 RID: 66242 RVA: 0x003E196F File Offset: 0x003DFB6F
		public void RefreshPage(bool bResetPosition = true)
		{
			this.RefreshList(bResetPosition);
			this.RefreshContent();
		}

		// Token: 0x060102C3 RID: 66243 RVA: 0x003E1984 File Offset: 0x003DFB84
		public void RefreshContent()
		{
			XPet curSelectedPet = this.doc.CurSelectedPet;
			bool flag = curSelectedPet == null;
			if (flag)
			{
				base.uiBehaviour.m_ContentFrame.SetActive(false);
			}
			else
			{
				base.uiBehaviour.m_ContentFrame.SetActive(true);
				this.RefreshBaseInfo();
				this.RefreshAttribute();
				this.RefreshExp();
				this.RefreshFullDegree();
				this.RefreshMood();
				this.RefreshPrivilege();
				base.uiBehaviour.m_FeedRedPoint.gameObject.SetActive(this.doc.HasRedPoint && curSelectedPet.UID == this.doc.CurFightUID);
			}
			this.m_SkillHandler.Refresh(curSelectedPet);
		}

		// Token: 0x060102C4 RID: 66244 RVA: 0x003E1A40 File Offset: 0x003DFC40
		public void RefreshPrivilege()
		{
			base.uiBehaviour.m_ExpPrivilegeSp.gameObject.SetActive(false);
		}

		// Token: 0x060102C5 RID: 66245 RVA: 0x003E1A5C File Offset: 0x003DFC5C
		public void RefreshPetModel()
		{
			bool flag = this.doc.CurSelectedPet == null;
			if (!flag)
			{
				XSingleton<XTimerMgr>.singleton.KillTimer(this._PlayActionTimerID);
				this.m_Dummy = XSingleton<X3DAvatarMgr>.singleton.CreateCommonEntityDummy(this.m_dummPool, XPetDocument.GetPresentID(this.doc.CurSelectedPet.ID), this.m_uiBehaviour.m_PetSnapshot, this.m_Dummy, 1f);
				this.PetActionChange(XPetActionFile.IDLE, this.doc.CurSelectedPet.ID, this.m_Dummy, true);
			}
		}

		// Token: 0x060102C6 RID: 66246 RVA: 0x003E1AF0 File Offset: 0x003DFCF0
		public void PlayPetLevelUpFx(Transform t, bool follow = false)
		{
			bool flag = !DlgBase<XPetMainView, XPetMainBehaviour>.singleton.IsVisible();
			if (!flag)
			{
				Vector3 scale = new Vector3(t.localScale.x / 300f, t.localScale.y / 300f, t.localScale.z / 300f);
				bool flag2 = this._LevelUpFx != null;
				if (flag2)
				{
					XSingleton<XFxMgr>.singleton.DestroyFx(this._LevelUpFx, true);
				}
				this._LevelUpFx = XSingleton<XFxMgr>.singleton.CreateAndPlay("Effects/FX_Particle/Roles/Lzg_Ty/P_level_up_02", t, Vector3.zero, scale, 1f, follow, 5f, true);
			}
		}

		// Token: 0x060102C7 RID: 66247 RVA: 0x003E1B98 File Offset: 0x003DFD98
		public void PlayPetMoodUpFx()
		{
			bool flag = !DlgBase<XPetMainView, XPetMainBehaviour>.singleton.IsVisible();
			if (!flag)
			{
				bool flag2 = this._MoodUpFx != null;
				if (flag2)
				{
					XSingleton<XFxMgr>.singleton.DestroyFx(this._MoodUpFx, true);
				}
				this._MoodUpFx = XSingleton<XFxMgr>.singleton.CreateAndPlay("Effects/FX_Particle/VehicleFX/Vehicle_weiyang", base.uiBehaviour.m_Fx, Vector3.zero, Vector3.one, 1f, false, 5f, true);
			}
		}

		// Token: 0x060102C8 RID: 66248 RVA: 0x003E1C10 File Offset: 0x003DFE10
		public void PlayPetEatUpFx()
		{
			bool flag = !DlgBase<XPetMainView, XPetMainBehaviour>.singleton.IsVisible();
			if (!flag)
			{
				bool flag2 = this._EatUpFx != null;
				if (flag2)
				{
					XSingleton<XFxMgr>.singleton.DestroyFx(this._EatUpFx, true);
				}
				this._EatUpFx = XSingleton<XFxMgr>.singleton.CreateAndPlay("Effects/FX_Particle/VehicleFX/Vehicle_weiyang_Clip01", base.uiBehaviour.m_Fx, Vector3.zero, Vector3.one, 1f, false, 5f, true);
			}
		}

		// Token: 0x060102C9 RID: 66249 RVA: 0x003E1C88 File Offset: 0x003DFE88
		public void PlayPetGetFx()
		{
			bool flag = !DlgBase<XPetMainView, XPetMainBehaviour>.singleton.IsVisible();
			if (!flag)
			{
				bool flag2 = this._GetFx != null;
				if (flag2)
				{
					XSingleton<XFxMgr>.singleton.DestroyFx(this._GetFx, true);
				}
				this._GetFx = XSingleton<XFxMgr>.singleton.CreateAndPlay("Effects/FX_Particle/UIfx/UI_yh", base.uiBehaviour.m_Fx, Vector3.zero, Vector3.one, 1f, true, 5f, true);
				XSingleton<XAudioMgr>.singleton.PlayUISound("Audio/UI/UI_Gethorse", true, AudioChannel.Action);
			}
		}

		// Token: 0x060102CA RID: 66250 RVA: 0x003E1D10 File Offset: 0x003DFF10
		public void SetPetSex(IXUISprite sp, PetSex sex)
		{
			bool flag = sex == PetSex.Girl;
			if (flag)
			{
				sp.SetSprite("zq_Gender0");
			}
			else
			{
				bool flag2 = sex == PetSex.Boy;
				if (flag2)
				{
					sp.SetSprite("zq_Gender1");
				}
				else
				{
					XSingleton<XDebug>.singleton.AddErrorLog("Pet Sex is Null", null, null, null, null, null);
				}
			}
			sp.MakePixelPerfect();
		}

		// Token: 0x060102CB RID: 66251 RVA: 0x003E1D6C File Offset: 0x003DFF6C
		public void RefreshBaseInfo()
		{
			XPet curSelectedPet = this.doc.CurSelectedPet;
			bool flag = curSelectedPet == null;
			if (!flag)
			{
				this.SetPetSex(base.uiBehaviour.m_Sex, curSelectedPet.Sex);
				base.uiBehaviour.m_Name.SetText(curSelectedPet.Name);
				base.uiBehaviour.m_PPT.SetText(curSelectedPet.PPT.ToString());
				base.uiBehaviour.m_Level.SetText(string.Format("Lv.{0}", curSelectedPet.showLevel.ToString()));
				base.uiBehaviour.m_ActivationSelected.SetActive(this.doc.CurFightUID == curSelectedPet.UID);
				string text = (this.doc.CurFightUID == curSelectedPet.UID) ? XSingleton<XStringTable>.singleton.GetString("ACTIVATED") : XSingleton<XStringTable>.singleton.GetString("ACTIVATION");
				base.uiBehaviour.m_ActivationLabel.SetText(text);
				text = ((this.doc.CurMount == curSelectedPet.UID) ? XSingleton<XStringTable>.singleton.GetString("PET_DOWN") : XSingleton<XStringTable>.singleton.GetString("PET_RIDE"));
				base.uiBehaviour.m_BtnMountLabel.SetText(text);
			}
		}

		// Token: 0x060102CC RID: 66252 RVA: 0x003E1EB4 File Offset: 0x003E00B4
		private void RefreshAttribute()
		{
			XPet curSelectedPet = this.doc.CurSelectedPet;
			bool flag = curSelectedPet == null;
			if (!flag)
			{
				PetInfoTable.RowData petInfo = XPetDocument.GetPetInfo(curSelectedPet.ID);
				BuffTable.RowData buffData = XSingleton<XBuffTemplateManager>.singleton.GetBuffData((int)petInfo.SpeedBuff, 1);
				bool flag2 = buffData == null;
				if (flag2)
				{
					XSingleton<XDebug>.singleton.AddErrorLog("Buff No Find!\nSp BuffId:" + petInfo.SpeedBuff, null, null, null, null, null);
				}
				bool flag3 = 1201 != (int)buffData.BuffChangeAttribute[0, 0];
				if (flag3)
				{
					XSingleton<XDebug>.singleton.AddErrorLog("Buff No Find XAttr_RUN_SPEED_Percent.\nSp BuffId:" + petInfo.SpeedBuff, null, null, null, null, null);
				}
				base.uiBehaviour.m_SpeedUp.SetText(string.Format("{0}%", (buffData.BuffChangeAttribute[0, 1] + 100f).ToString()));
				PetLevelTable.RowData petLevel = XPetDocument.GetPetLevel(curSelectedPet);
				PetLevelTable.RowData petLevel2 = XPetDocument.GetPetLevel(curSelectedPet.ID, curSelectedPet.Level + 1);
				base.uiBehaviour.m_AttributePool.ReturnAll(false);
				int num = 0;
				while ((long)num < (long)((ulong)XPetMainView.ATTRIBUTE_NUM_MAX))
				{
					bool flag4 = num >= petLevel.PetsAttributes.Count;
					if (!flag4)
					{
						GameObject gameObject = base.uiBehaviour.m_AttributePool.FetchGameObject(false);
						int spriteHeight = (gameObject.transform.GetComponent("XUISprite") as IXUISprite).spriteHeight;
						IXUILabel ixuilabel = gameObject.transform.Find("AttributeName").GetComponent("XUILabel") as IXUILabel;
						IXUILabel ixuilabel2 = gameObject.transform.Find("AttributeName/AttributeVal").GetComponent("XUILabel") as IXUILabel;
						IXUILabel ixuilabel3 = gameObject.transform.Find("AttributeName/GrowUp").GetComponent("XUILabel") as IXUILabel;
						gameObject.transform.localPosition = new Vector3(0f, (float)(-(float)spriteHeight * num), 0f);
						string attrStr = XAttributeCommon.GetAttrStr((int)petLevel.PetsAttributes[num, 0]);
						ixuilabel.SetText(attrStr);
						uint num2 = 0U;
						for (int i = 1; i <= curSelectedPet.Level; i++)
						{
							PetLevelTable.RowData petLevel3 = XPetDocument.GetPetLevel(curSelectedPet.ID, i);
							num2 += petLevel3.PetsAttributes[num, 1];
						}
						ixuilabel2.SetText(XAttributeCommon.GetAttrValueStr(petLevel.PetsAttributes[num, 0], num2, false));
						bool flag5 = petLevel2 != null;
						if (flag5)
						{
							ixuilabel3.SetText(string.Format("+{0}", petLevel2.PetsAttributes[num, 1].ToString()));
						}
						else
						{
							ixuilabel3.SetText("");
						}
					}
					num++;
				}
			}
		}

		// Token: 0x060102CD RID: 66253 RVA: 0x003E219C File Offset: 0x003E039C
		public void RefreshExp()
		{
			XPet curSelectedPet = this.doc.CurSelectedPet;
			bool flag = curSelectedPet == null;
			if (!flag)
			{
				bool flag2 = this.doc.IsMaxLevel(curSelectedPet.ID, curSelectedPet.showLevel);
				if (flag2)
				{
					base.uiBehaviour.m_Exp.SetText(XSingleton<XStringTable>.singleton.GetString("PET_LEVEL_MAX_TIP"));
					base.uiBehaviour.m_ExpBar.value = 0f;
					base.uiBehaviour.m_ExpBarLevel.SetText(string.Format("Lv.{0}", curSelectedPet.showLevel.ToString()));
					this.doc.InPlayExpUp = false;
				}
				else
				{
					int num;
					int num2;
					this.doc.GetExpInfo(curSelectedPet, out num, out num2);
					base.uiBehaviour.m_Exp.SetText(string.Format("{0}/{1}", num, num2));
					base.uiBehaviour.m_ExpBar.value = Math.Min((float)num / (float)num2, 1f);
					base.uiBehaviour.m_ExpBarLevel.SetText(string.Format("Lv.{0}", curSelectedPet.showLevel.ToString()));
				}
			}
		}

		// Token: 0x060102CE RID: 66254 RVA: 0x003E22D0 File Offset: 0x003E04D0
		public void RefreshFullDegree()
		{
			XPet curSelectedPet = this.doc.CurSelectedPet;
			bool flag = curSelectedPet == null;
			if (!flag)
			{
				PetInfoTable.RowData petInfo = XPetDocument.GetPetInfo(curSelectedPet.ID);
				uint maxHungry = petInfo.maxHungry;
				bool flag2 = maxHungry == 0U;
				if (flag2)
				{
					XSingleton<XDebug>.singleton.AddErrorLog("FullDegreeMAX = 0", null, null, null, null, null);
				}
				else
				{
					base.uiBehaviour.m_FullDegree.SetText(string.Format("{0}%", curSelectedPet.showFullDegree));
					base.uiBehaviour.m_FullDegreeBar.value = curSelectedPet.showFullDegree / maxHungry;
					bool flag3 = (ulong)curSelectedPet.showFullDegree >= (ulong)((long)int.Parse(this.doc.ColorLevel[0]));
					Color color;
					if (flag3)
					{
						color = new Color(0.6784314f, 0.8392157f, 0.09019608f);
					}
					else
					{
						bool flag4 = (ulong)curSelectedPet.showFullDegree >= (ulong)((long)int.Parse(this.doc.ColorLevel[1]));
						if (flag4)
						{
							color = new Color(1f, 0.47058824f, 0.12156863f);
						}
						else
						{
							color = new Color(0.89411765f, 0.26666668f, 0.26666668f);
						}
					}
					base.uiBehaviour.m_FullDegreeColor.SetColor(color);
				}
			}
		}

		// Token: 0x060102CF RID: 66255 RVA: 0x003E241C File Offset: 0x003E061C
		public void RefreshMood()
		{
			XPet curSelectedPet = this.doc.CurSelectedPet;
			bool flag = curSelectedPet == null;
			if (!flag)
			{
				PetMoodTipsTable.RowData petMoodTip = this.doc.GetPetMoodTip(curSelectedPet.Mood);
				bool flag2 = petMoodTip != null;
				if (flag2)
				{
					base.uiBehaviour.m_MoodLevel.SetText(petMoodTip.tip);
					base.uiBehaviour.m_MoodIcon.SetSprite(petMoodTip.icon);
				}
			}
		}

		// Token: 0x060102D0 RID: 66256 RVA: 0x003E248C File Offset: 0x003E068C
		public void RefreshList(bool bResetPosition = true)
		{
			int num = Math.Min(this.doc.PetCountMax, (int)(this.doc.PetSeat + 1U));
			base.uiBehaviour.m_WrapContent.SetContentCount(num, false);
			if (bResetPosition)
			{
				base.uiBehaviour.m_PetListScrollView.ResetPosition();
			}
			else
			{
				base.uiBehaviour.m_WrapContent.RefreshAllVisibleContents();
			}
		}

		// Token: 0x060102D1 RID: 66257 RVA: 0x003E24F4 File Offset: 0x003E06F4
		public void SetTravelSetBtnStatus()
		{
			bool flag = this.doc.CurSelectedPet != null;
			if (flag)
			{
				PetInfoTable.RowData petInfo = XPetDocument.GetPetInfo(this.doc.CurSelectedPet.ID);
				base.uiBehaviour.m_TravelSet.gameObject.SetActive(petInfo != null && petInfo.PetType == 1U);
			}
		}

		// Token: 0x060102D2 RID: 66258 RVA: 0x003E2554 File Offset: 0x003E0754
		private void _OnPetListItemUpdated(Transform t, int index)
		{
			bool flag = index < 0;
			if (flag)
			{
				XSingleton<XDebug>.singleton.AddErrorLog("index:" + index, null, null, null, null, null);
			}
			else
			{
				List<XPet> pets = this.doc.Pets;
				IXUILabel ixuilabel = t.Find("Level").GetComponent("XUILabel") as IXUILabel;
				IXUISprite ixuisprite = t.Find("Item/PetIcon").GetComponent("XUISprite") as IXUISprite;
				IXUISprite ixuisprite2 = t.Find("Item/Quality").GetComponent("XUISprite") as IXUISprite;
				GameObject gameObject = t.Find("Mount").gameObject;
				GameObject gameObject2 = t.Find("Fight").gameObject;
				IXUISprite ixuisprite3 = t.Find("Unlock").GetComponent("XUISprite") as IXUISprite;
				GameObject gameObject3 = t.Find("New").gameObject;
				GameObject gameObject4 = t.Find("Selected").gameObject;
				GameObject gameObject5 = t.Find("Item").gameObject;
				GameObject gameObject6 = t.Find("RedPoint").gameObject;
				gameObject3.SetActive(false);
				gameObject6.SetActive(false);
				bool flag2 = index >= pets.Count;
				if (flag2)
				{
					ixuilabel.SetText("");
					gameObject5.SetActive(false);
					gameObject.SetActive(false);
					gameObject2.SetActive(false);
					gameObject4.SetActive(false);
					bool flag3 = (long)index >= (long)((ulong)this.doc.PetSeat);
					if (flag3)
					{
						ixuisprite3.gameObject.SetActive(true);
						ixuisprite3.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this._OnUnlockClicked));
					}
					else
					{
						ixuisprite3.gameObject.SetActive(false);
					}
				}
				else
				{
					bool flag4 = this.doc.HasNewPet && index == pets.Count - 1;
					if (flag4)
					{
						gameObject3.SetActive(true);
					}
					XPet xpet = pets[index];
					gameObject5.SetActive(true);
					ixuilabel.SetText("Lv." + xpet.showLevel);
					gameObject4.SetActive(index == this.doc.CurSelectedIndex);
					gameObject.SetActive(xpet.UID == this.doc.CurMount);
					gameObject2.SetActive(xpet.UID == this.doc.CurFightUID);
					ixuisprite3.gameObject.SetActive(false);
					gameObject6.SetActive(xpet.UID == this.doc.CurFightUID && this.doc.HasRedPoint);
					PetInfoTable.RowData petInfo = XPetDocument.GetPetInfo(xpet.ID);
					bool flag5 = petInfo != null;
					if (flag5)
					{
						ixuisprite.SetSprite(petInfo.icon, petInfo.Atlas, false);
					}
					ixuisprite2.SetSprite(XSingleton<UiUtility>.singleton.GetItemQualityFrame((int)petInfo.quality, 0));
					ixuisprite.ID = (ulong)((long)index);
					ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this._OnPetClicked));
				}
			}
		}

		// Token: 0x060102D3 RID: 66259 RVA: 0x003E2868 File Offset: 0x003E0A68
		private void _OnUnlockClicked(IXUISprite iSp)
		{
			bool flag = (ulong)this.doc.PetSeat < (ulong)((long)this.doc.PetSeatBuy.Length);
			if (flag)
			{
				XSingleton<UiUtility>.singleton.ShowModalDialog(string.Format(XStringDefineProxy.GetString("PET_SEAT_BUY"), this.doc.PetSeatBuy[(int)this.doc.PetSeat]), XStringDefineProxy.GetString("COMMON_OK"), XStringDefineProxy.GetString("COMMON_CANCEL"), new ButtonClickEventHandler(this._BuySeat));
			}
			else
			{
				XSingleton<XDebug>.singleton.AddErrorLog(string.Concat(new object[]
				{
					"PetSeat:",
					this.doc.PetSeat,
					"\nPetSeatMAX",
					this.doc.PetSeatBuy.Length
				}), null, null, null, null, null);
			}
		}

		// Token: 0x060102D4 RID: 66260 RVA: 0x003E2940 File Offset: 0x003E0B40
		private bool _BuySeat(IXUIButton btn)
		{
			this.doc.ReqBuySeat();
			XSingleton<UiUtility>.singleton.CloseModalDlg();
			return true;
		}

		// Token: 0x060102D5 RID: 66261 RVA: 0x003E296C File Offset: 0x003E0B6C
		private void _OnPetClicked(IXUISprite iSp)
		{
			int index = (int)iSp.ID;
			this.doc.Select(index, false);
		}

		// Token: 0x060102D6 RID: 66262 RVA: 0x003E2990 File Offset: 0x003E0B90
		private bool _OnMountClicked(IXUIButton btn)
		{
			this.doc.ReqMount();
			return true;
		}

		// Token: 0x060102D7 RID: 66263 RVA: 0x003E29B0 File Offset: 0x003E0BB0
		private bool _OnSkillLearnClicked(IXUIButton btn)
		{
			this.SkillLearnHandler.SetVisible(true);
			return true;
		}

		// Token: 0x060102D8 RID: 66264 RVA: 0x003E29D0 File Offset: 0x003E0BD0
		private bool _OnActivationClicked(IXUIButton btn)
		{
			this.doc.ReqFight();
			return true;
		}

		// Token: 0x060102D9 RID: 66265 RVA: 0x003E29EF File Offset: 0x003E0BEF
		public override void LeaveStackTop()
		{
			base.LeaveStackTop();
			base.Return3DAvatarPool();
		}

		// Token: 0x060102DA RID: 66266 RVA: 0x003E2A00 File Offset: 0x003E0C00
		private bool _OnThrowClicked(IXUIButton btn)
		{
			XSingleton<UiUtility>.singleton.ShowModalDialog(string.Format(XSingleton<UiUtility>.singleton.ReplaceReturn(XSingleton<XStringTable>.singleton.GetString("PET_THROW")), this.doc.CurSelectedPet.Name), XStringDefineProxy.GetString("COMMON_OK"), XStringDefineProxy.GetString("COMMON_CANCEL"), new ButtonClickEventHandler(this._PetThrow));
			return true;
		}

		// Token: 0x060102DB RID: 66267 RVA: 0x003E2A6C File Offset: 0x003E0C6C
		private bool _OnExpTransferClicked(IXUIButton btn)
		{
			bool flag = this.doc.Pets.Count < 2;
			bool result;
			if (flag)
			{
				XSingleton<UiUtility>.singleton.ShowSystemTip(XSingleton<XStringTable>.singleton.GetString("PET_TRANSFER_NOT_ENOUGH_TIP"), "fece00");
				result = false;
			}
			else
			{
				bool flag2 = this.doc.CurSelectedPet == null;
				if (flag2)
				{
					XSingleton<UiUtility>.singleton.ShowSystemTip(XSingleton<XStringTable>.singleton.GetString("PET_NO_SELECT"), "fece00");
					result = false;
				}
				else
				{
					this.ExpTransferHandler.SetVisible(true);
					result = true;
				}
			}
			return result;
		}

		// Token: 0x060102DC RID: 66268 RVA: 0x003E2B00 File Offset: 0x003E0D00
		private bool _OnTravelSetClicked(IXUIButton btn)
		{
			bool flag = this.m_setHandler != null;
			if (flag)
			{
				this.m_setHandler.SetVisible(true);
			}
			return true;
		}

		// Token: 0x060102DD RID: 66269 RVA: 0x003E2B30 File Offset: 0x003E0D30
		private bool _PetThrow(IXUIButton btn)
		{
			this.doc.ReqRelease();
			XSingleton<UiUtility>.singleton.CloseModalDlg();
			return true;
		}

		// Token: 0x060102DE RID: 66270 RVA: 0x003E2B5C File Offset: 0x003E0D5C
		private void AutoRefresh(object param)
		{
			bool flag = base.IsVisible() && this.doc.CurSelectedPet != null;
			if (flag)
			{
				bool flag2 = !this.doc.InPlayExpUp;
				if (flag2)
				{
					this.doc.ReqPetInfo();
				}
				this._RefreshDataTimerID = XSingleton<XTimerMgr>.singleton.SetTimer(30f, new XTimerMgr.ElapsedEventHandler(this.AutoRefresh), null);
				this.doc.PlayRandAction();
			}
		}

		// Token: 0x060102DF RID: 66271 RVA: 0x003E2BD8 File Offset: 0x003E0DD8
		public void RefreshAutoRefresh()
		{
			XSingleton<XTimerMgr>.singleton.KillTimer(this._RefreshDataTimerID);
			bool flag = base.IsVisible() && this.doc.CurSelectedPet != null;
			if (flag)
			{
				bool flag2 = !this.doc.InPlayExpUp;
				if (flag2)
				{
					this.doc.ReqPetInfo();
				}
				this._RefreshDataTimerID = XSingleton<XTimerMgr>.singleton.SetTimer(10f, new XTimerMgr.ElapsedEventHandler(this.AutoRefresh), null);
			}
		}

		// Token: 0x060102E0 RID: 66272 RVA: 0x003E2C58 File Offset: 0x003E0E58
		private void RefreshAction(object param)
		{
			bool flag = !DlgBase<XPetMainView, XPetMainBehaviour>.singleton.IsVisible();
			if (!flag)
			{
				base.uiBehaviour.m_Talk.gameObject.SetActive(false);
				this.doc.PlayIdleAction();
			}
		}

		// Token: 0x060102E1 RID: 66273 RVA: 0x003E2C9C File Offset: 0x003E0E9C
		private void CloseBubble(object param)
		{
			bool flag = !DlgBase<XPetMainView, XPetMainBehaviour>.singleton.IsVisible();
			if (!flag)
			{
				base.uiBehaviour.m_Talk.gameObject.SetActive(false);
			}
		}

		// Token: 0x060102E2 RID: 66274 RVA: 0x003E2CD4 File Offset: 0x003E0ED4
		public void PetActionChange(XPetActionFile Action, uint petID, XDummy m_Dummy, bool init = false)
		{
			bool flag = m_Dummy == null;
			if (!flag)
			{
				XPetDocument specificDocument = XDocuments.GetSpecificDocument<XPetDocument>(XPetDocument.uuID);
				PetBubble.RowData petBubble = specificDocument.GetPetBubble(Action, petID);
				string sefile = petBubble.SEFile;
				bool flag2 = !string.IsNullOrEmpty(sefile);
				if (flag2)
				{
					XSingleton<XAudioMgr>.singleton.PlayUISound(sefile, true, AudioChannel.Action);
				}
				string actionFile = petBubble.ActionFile;
				float length = m_Dummy.SetAnimationGetLength(actionFile);
				XSingleton<XDebug>.singleton.AddLog("Pet Action:" + Action, null, null, null, null, null, XDebugColor.XDebug_None);
				bool flag3 = Action == XPetActionFile.IDLE;
				if (flag3)
				{
					this._PetStatus = XPetMainView.PetStatus.IDLE;
					this.PlayActionTime(length);
				}
				bool flag4 = Action == XPetActionFile.IDLE_PEOPLE;
				if (flag4)
				{
					this._PetStatus = XPetMainView.PetStatus.IDLE_PEOPLE;
					this.PlayActionTime(length);
				}
				bool flag5 = Action == XPetActionFile.EAT;
				if (flag5)
				{
					bool flag6 = this._PetStatus != XPetMainView.PetStatus.EAT;
					if (flag6)
					{
						this._PetStatus = XPetMainView.PetStatus.EAT;
						this.PlayActionTime(length);
						this.PlayBubble(petBubble);
					}
				}
				bool flag7 = Action == XPetActionFile.CARESS;
				if (flag7)
				{
					bool flag8 = this._PetStatus != XPetMainView.PetStatus.CARESS;
					if (flag8)
					{
						this._PetStatus = XPetMainView.PetStatus.CARESS;
						this.PlayActionTime(length);
						this.PlayBubble(petBubble);
					}
				}
				bool flag9 = Action == XPetActionFile.LOSE || Action == XPetActionFile.HAPPY || Action == XPetActionFile.SLEEP || Action == XPetActionFile.HUNGER;
				if (flag9)
				{
					bool flag10 = this._PetStatus == XPetMainView.PetStatus.IDLE;
					if (flag10)
					{
						this._PetStatus = XPetMainView.PetStatus.Rand;
						this.PlayActionTime(length);
						this.PlayBubble(petBubble);
					}
				}
			}
		}

		// Token: 0x060102E3 RID: 66275 RVA: 0x003E2E54 File Offset: 0x003E1054
		private void PlayActionTime(float length)
		{
			XSingleton<XTimerMgr>.singleton.KillTimer(this._PlayActionTimerID);
			bool flag = length > 0f;
			if (flag)
			{
				this._PlayActionTimerID = XSingleton<XTimerMgr>.singleton.SetTimer(length, new XTimerMgr.ElapsedEventHandler(this.RefreshAction), null);
			}
		}

		// Token: 0x060102E4 RID: 66276 RVA: 0x003E2EA0 File Offset: 0x003E10A0
		private void PlayBubble(PetBubble.RowData petBubbleData)
		{
			string text = this.doc.RandomPlayBubble(petBubbleData.Bubble);
			bool flag = !string.IsNullOrEmpty(text);
			if (flag)
			{
				base.uiBehaviour.m_Talk.gameObject.SetActive(true);
				base.uiBehaviour.m_TalkLabel.SetText(text);
				XSingleton<XTimerMgr>.singleton.KillTimer(this._PlayBubbleTimerID);
				this._PlayBubbleTimerID = XSingleton<XTimerMgr>.singleton.SetTimer(petBubbleData.BubbleTime, new XTimerMgr.ElapsedEventHandler(this.CloseBubble), null);
			}
		}

		// Token: 0x040073D5 RID: 29653
		private XPetDocument doc;

		// Token: 0x040073D6 RID: 29654
		private XFoodSelectorHandler m_FoodSelectorHandler;

		// Token: 0x040073D7 RID: 29655
		private PairsPetSetHandler m_setHandler;

		// Token: 0x040073D8 RID: 29656
		public XDummy m_Dummy;

		// Token: 0x040073D9 RID: 29657
		private XPetSkillHandler m_SkillHandler;

		// Token: 0x040073DA RID: 29658
		public PetExpTransferHandler ExpTransferHandler;

		// Token: 0x040073DB RID: 29659
		public PetSkillLearnHandler SkillLearnHandler;

		// Token: 0x040073DC RID: 29660
		public static readonly uint STAR_MAX = 10U;

		// Token: 0x040073DD RID: 29661
		public static readonly uint ATTRIBUTE_NUM_MAX = 10U;

		// Token: 0x040073DE RID: 29662
		private uint _RefreshDataTimerID = 0U;

		// Token: 0x040073DF RID: 29663
		private uint _PlayActionTimerID = 0U;

		// Token: 0x040073E0 RID: 29664
		private uint _PlayBubbleTimerID = 0U;

		// Token: 0x040073E1 RID: 29665
		private XPetMainView.PetStatus _PetStatus;

		// Token: 0x040073E2 RID: 29666
		public XFx _LevelUpFx;

		// Token: 0x040073E3 RID: 29667
		private XFx _MoodUpFx;

		// Token: 0x040073E4 RID: 29668
		private XFx _EatUpFx;

		// Token: 0x040073E5 RID: 29669
		private XFx _GetFx;

		// Token: 0x02001A17 RID: 6679
		private enum PetStatus
		{
			// Token: 0x04008243 RID: 33347
			IDLE,
			// Token: 0x04008244 RID: 33348
			IDLE_PEOPLE,
			// Token: 0x04008245 RID: 33349
			Rand,
			// Token: 0x04008246 RID: 33350
			EAT,
			// Token: 0x04008247 RID: 33351
			CARESS
		}
	}
}
